package com.jiuyou.clientController.mall.classify;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.shopping.domain.MallClassify;
import com.ruoyi.shopping.service.IMallClassifyService;
import com.ruoyi.storeclassify.domain.Storeclassify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chengliang
 * @date 2022/6/16
 **/
@RestController
@RequestMapping("/client/mall/classify")
public class MallClassifyClientController {
    @Autowired
    private IMallClassifyService service;
    @PostMapping("/listFirst")
    public List<MallClassify> listFirst(){
        MallClassify cl = new MallClassify();
        cl.setParentId(0L);
        return service.selectMallClassifyList(cl);
    }
    @PostMapping("/getHot")
    public AjaxResult getHot()
    {
        MallClassify classify=new MallClassify();
        classify.setRecommend("Y");
        classify.setStatus(DicConstants.SYS_Y.getCode());
        List<MallClassify> list = service.selectMallClassifyList(classify);
        Map<Long, JSONObject> map=new HashMap<>();
        for (MallClassify mallClassify:list) {
            JSONObject jso=new JSONObject();
            jso.put("classifyName",mallClassify.getClassifyName());
            jso.put("id",mallClassify.getId());
            jso.put("img",mallClassify.getClassifyImg());
            map.put(mallClassify.getId(),jso);
        }
        return AjaxResult.success(map.values());
    }
    @PostMapping("/getSecond/{id}")
    public AjaxResult getHot(@PathVariable Long id)
    {
        MallClassify classify=new MallClassify();
        classify.setParentId(id);
        classify.setStatus(DicConstants.SYS_Y.getCode());
        List<MallClassify> list = service.selectMallClassifyList(classify);
        Map<Long, JSONObject> map=new HashMap<>();
        for (MallClassify mallClassify:list) {
            JSONObject jso=new JSONObject();
            jso.put("classifyName",mallClassify.getClassifyName());
            jso.put("id",mallClassify.getId());
            jso.put("img",mallClassify.getClassifyImg());
            map.put(mallClassify.getId(),jso);
        }
        return AjaxResult.success(map.values());
    }
}
